<template>
  <div>
    <el-dialog
      title="查看"
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
    >
      <el-tabs v-model="activeName">
        <el-tab-pane label="产品信息" name="first">
          <div class="listItem">
            <div class="list">
              <div class="item">
                <label>产品序号：</label><span>{{ dataForm.code }}</span>
              </div>
            </div>
            <div class="list">
              <div class="item">
                <label>产品类型：</label><span>{{ dataForm.type }}</span>
              </div>
            </div>
            <div class="list">
              <div class="item">
                <label>型号：</label><span>{{ dataForm.model }}</span>
              </div>
            </div>
            <div class="list">
              <div class="item">
                <label>合同编号：</label
                ><span>{{ dataForm.contractNumber }}</span>
              </div>
            </div>
            <div class="list">
              <div class="item">
                <label>频率：</label><span>{{ dataForm.frequency }}</span>
              </div>
            </div>
            <div class="list">
              <div class="item">
                <label>额定电压：</label
                ><span>{{ dataForm.ratedVoltage }}</span>
              </div>
            </div>
            <div class="list">
              <div class="item">
                <label>额定电流：</label
                ><span>{{ dataForm.ratedCurrent }}</span>
              </div>
            </div>
            <div class="list">
              <div class="item">
                <label>执行标准：</label><span>{{ dataForm.standard }}</span>
              </div>
            </div>
            <div class="list itemfile">
              <div class="item"><label>产品图纸：</label></div>
              <!-- <div class="imgList">
                <div v-for="item in fileList" class="imgItem">
                  <img class="imgitem-thumbnail" :src="item.url" alt="">
                  <span class="imgitem-actions">
                    <span class="imgitem-preview" @click="handlePictureCardPreview(item)">
                      <i class="el-icon-zoom-in"></i>
                    </span>
                    <span class="imgitem-delete" @click="handleDownloadImg(item)">
                      <i class="el-icon-download"></i>
                    </span>
                  </span>
                </div>
              </div> -->
              <el-upload
                class="upload-demo"
                action="#"
                :on-preview="handlePreview"
                :file-list="fileList"
                disabled
              ></el-upload>
            </div>
            <div class="list itemfile">
              <div class="item"><label>试验报告：</label></div>
              <el-upload
                class="upload-demo"
                action="#"
                :on-preview="handlePreview"
                :file-list="fileList2"
                disabled
              ></el-upload>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="激活详情" name="second">
          <div class="listItem" v-if="dataForm.activateState">
            <div class="list" v-if="dataForm.activateState">
              <div class="item">
                <label>签到地址:</label
                ><span>{{ dataForm.activateAddress }}</span>
              </div>
            </div>
            <div class="list" v-if="dataForm.activateState">
              <div class="item">
                <label>签到时间:</label><span>{{ dataForm.activateTime }}</span>
              </div>
            </div>
            <div class="list">
              <div class="item">
                <label>司机：</label><span>{{ dataForm.driverName }}</span>
              </div>
            </div>
            <div class="list">
              <div class="item">
                <label>司机联系电话：</label
                ><span>{{ dataForm.driverPhone }}</span>
              </div>
            </div>
            <div
              class="list"
              style="display: flex"
              v-if="dataForm.activateState"
            >
              <div class="item"><label>图片:</label></div>
              <div class="imgList">
                <div v-for="item in fileList3" class="imgItem">
                  <img class="imgitem-thumbnail" :src="item.url" alt="" />
                  <span class="imgitem-actions">
                    <span
                      class="imgitem-preview"
                      @click="handlePictureCardPreview(item)"
                    >
                      <i class="el-icon-zoom-in"></i>
                    </span>
                    <span
                      class="imgitem-delete"
                      @click="handleDownloadImg(item)"
                    >
                      <i class="el-icon-download"></i>
                    </span>
                  </span>
                </div>
              </div>
            </div>
          </div>
          <div
            v-if="!dataForm.activateState"
            style="text-align: center; color: #999"
          >
            暂未激活
          </div>
        </el-tab-pane>
      </el-tabs>

      <template #footer>
        <span class="dialog-footer">
          <el-button size="small" @click="dialogFormVisible = false"
            >关 闭</el-button
          >
          <!-- <el-button size="small" type="primary" @click="dataFormSubmit()" :disabled="isDisabled">确 定</el-button> -->
        </span>
      </template>
    </el-dialog>
    <el-dialog
      :visible.sync="dialogVisibleImg"
      width="50%"
      style="height: 100%"
    >
      <div style="height: 60%">
        <img style="max-width: 100%" :src="dialogImageUrl" alt="" />
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { v4 as uuidv4 } from "uuid";
import { getToken } from "@/utils/auth";
export default {
  emits: ["refreshDataList"],
  data() {
    return {
      dialogFormVisible: false,
      isDisabled: false,
      dataForm: {
        id: 0,
        code: "", //产品序号
        driverId: "", //关联送货司机
        frequency: "", //频率
        model: "", //型号
        projectId: "", //关联项目
        ratedCurrent: "", //额定电流
        ratedVoltage: "", //额定电压
        standard: "", //执行标准
        type: "", //产品类型
        appendixName: "", //附件名称
        appendixUrl: "", //附件路径
        activateState: false,
        driverName: "",
        driverPhone: "",
        contractNumber: "",
      },
      activeName: "first",
      projectList: [],
      driverList: [],
      fileList: [],
      fileList2: [],
      fileList3: [],
      dialogVisibleImg: false,
      dialogImageUrl: "",
      url: process.env.VUE_APP_BASE_API,
      headers: {
        token: getToken(), //从cookie里获取token，并赋值  Authorization ，而不是token
      },
      dataRule: {
        // driverName: [
        //   { required: true, message: '司机姓名必填' },
        // ],
        // driverPhone: [
        //   { required: true, message: '司机联系电话必填' },
        // ],
        // licenseNumber: [
        //   { required: true, message: '车牌号必须填写' },
        // ]
      },
      formLabelWidth: "140px",
    };
  },
  created() {},
  methods: {
    async init(id) {
      this.dataForm.id = id || 0;
      this.dialogFormVisible = true;
      this.$nextTick(async () => {
        // this.$refs["dataForm"].resetFields();
        this.fileList = [];
        this.fileList2 = [];
        this.fileList3 = [];
        this.projectList = [];
        this.dataForm.activateState = false;
        this.driverList = [];
        await this.Sevice({
          url: "/project/list",
          method: "get",
        }).then(async (res) => {
          if (res.code != 200) {
          } else {
            this.projectList = res.list;
          }
        });
        if (!this.dataForm.id) {
          // 新增
          // this.treeListTreeSetCurrentNode()
        } else {
          //获取详情
          this.Sevice({
            url: "/product/info/" + this.dataForm.id,
            method: "get",
          }).then(async (res) => {
            // console.log(res);
            if (res.code != 200) {
              // this.$message.error(res.data.msg)
            } else {
              this.dataForm.id = res.info.id;
              this.dataForm.activateState = res.info.activateState;
              this.dataForm.code = res.info.code;
              this.dataForm.driverId = res.info.driverId;
              this.dataForm.frequency = res.info.frequency;
              this.dataForm.model = res.info.model;
              this.dataForm.projectId = res.info.projectId;
              this.dataForm.ratedCurrent = res.info.ratedCurrent;
              this.dataForm.ratedVoltage = res.info.ratedVoltage;
              this.dataForm.standard = res.info.standard;
              this.dataForm.type = res.info.type;
              this.dataForm.contractNumber = res.info.contractNumber;
              // this.dataForm.appendixUrl = res.info.appendixUrl;
              // this.dataForm.appendixName = res.info.appendixName;
              // this.getDriver(res.info.projectId)
              //附件
              if (res.info.appendixUrl) {
                let appendixUrl = res.info.appendixUrl.split(",");
                let appendixName = res.info.appendixName.split(",");
                let list = [];
                for (let i = 0; i < appendixUrl.length; i++) {
                  list.push({ url: appendixUrl[i], name: appendixName[i] });
                }
                this.fileList2 = list;
              }
              //图纸
              if (res.info.picUrl) {
                let picUrl = res.info.picUrl.split(",");
                let picName = res.info.picName.split(",");
                let list = [];
                for (let i = 0; i < picUrl.length; i++) {
                  list.push({
                    url: this.url + picUrl[i],
                    name: picName[i],
                    response: {
                      map: {
                        filePath: picUrl[i],
                        fileName: picName[i],
                      },
                    },
                  });
                }
                this.fileList = list;
              }
            }
          });
          //获取详情
          this.Sevice({
            url: "/product/activate/" + this.dataForm.id,
            method: "get",
          }).then(async (res) => {
            // console.log(res);
            if (res.code != 200) {
              // this.$message.error(res.data.msg)
            } else {
              this.dataForm.activateAddress = res.info.activateAddress;
              this.dataForm.activateTime = res.info.activateTime;
              // this.dataForm.appendixName = res.info.appendixName
              // this.dataForm.appendixUrl = res.info.appendixUrl
              this.dataForm.driverName = res.info.driverName;
              this.dataForm.driverPhone = res.info.driverPhone;
              this.dataForm.productId = res.info.productId;
              this.dataForm.id = res.info.id;
              if (res.info.appendixUrl) {
                let appendixUrl = res.info.appendixUrl.split(",");
                let appendixName = res.info.appendixName.split(",");
                let list = [];
                for (let i = 0; i < appendixUrl.length; i++) {
                  list.push({
                    url: this.url + appendixUrl[i],
                    name: appendixName[i],
                    response: {
                      map: {
                        filePath: appendixUrl[i],
                        fileName: appendixName[i],
                      },
                    },
                  });
                }
                this.fileList3 = list;
              }
            }
          });
        }
      });
    },
    handlePreview(file) {
      this.fileDown(file);
    },
    projectChange(id) {
      this.getDriver(id);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisibleImg = true;
    },
    handleDownloadImg(file) {
      this.getImge(file);
      this.fileDown(file);
    },
    //获取司机
    getDriver(id) {
      this.Sevice({
        url: "/project/info/" + id,
        method: "get",
      }).then(async (res) => {
        // console.log(res);
        if (res.code != 200) {
          // this.$message.error(res.data.msg)
        } else {
          this.driverList = res.info.projectDrivers;
          for (let i = 0; i < this.driverList.length; i++) {
            if (this.dataForm.driverId == this.driverList[i].id) {
              this.dataForm.driverName = this.driverList[i].driverName;
              this.dataForm.driverPhone = this.driverList[i].driverPhone;
              this.dataForm.licenseNumber = this.driverList[i].licenseNumber;
              console.log(
                this.dataForm.driverPhone,
                this.dataForm.licenseNumber
              );
            }
          }
        }
      });
    },
    // 表单提交
    async dataFormSubmit() {},
  },
};
</script>

<style scoped>
.mod-menu .menu-list__input > .el-input__inner,
.mod-menu .icon-list__input > .el-input__inner {
  cursor: pointer;
}

.mod-menu__icon-popover {
  width: 458px;
  overflow: hidden;
}

.mod-menu__icon-inner {
  width: 478px;
  max-height: 258px;
  overflow-x: hidden;
  overflow-y: auto;
}

.mod-menu__icon-list {
  width: 458px;
  padding: 0;
  margin: -8px 0 0 -8px;
}

.mod-menu__icon-list > .el-button {
  padding: 8px;
  margin: 8px 0 0 8px;
}

.mod-menu__icon-list > .el-button > span {
  display: inline-block;
  vertical-align: middle;
  width: 18px;
  height: 18px;
  font-size: 18px;
}

.mod-menu .icon-list__tips {
  font-size: 18px;
  text-align: center;
  color: #e6a23c;
  cursor: pointer;
}

.el-tree {
  height: 200px;
  overflow-y: auto;
}

.item {
  display: flex;
  padding: 5px 0;
}

.item label {
  margin-right: 10px;
  min-width: 145px;
}

.item span {
  width: calc(100% - 145px);
  /* padding: 5px 0; */
  line-height: 26px;

  /* border-bottom: 1px solid #ccc; */
}

.items div {
  padding-left: 10px;
  line-height: 26px;
}

.list label {
  /* padding: 5px 0; */
  line-height: 26px;
  color: #999;
}

.list {
  /* border-bottom: 1px solid #ccc; */
}

.listItem {
  /* box-shadow: 0px 0px 3px #ccc;
  padding: 10px; */
  font-family: dengxian;
}

.texareastyle {
  text-indent: 28px;
  padding: 5px 28px !important;
  border: 1px solid #ccc;
  min-height: 100px;
  border-radius: 10px;
}

.imgList {
  display: flex;
  flex-wrap: wrap;
}

.imgItem {
  overflow: hidden;
  background-color: #fff;
  border: 1px solid #c0ccda;
  border-radius: 6px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  width: 148px;
  height: 148px;
  margin: 0 8px 8px 0;
  position: relative;
}

.imgitem-thumbnail {
  width: 100%;
  /* height: 100%; */
}

.imgitem-actions {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  cursor: default;
  text-align: center;
  color: #fff;
  opacity: 0;
  font-size: 20px;
  background-color: rgba(0, 0, 0, 0.5);
  transition: opacity 0.3s;
  display: flex;
  justify-content: center;
  align-items: center;
}

.imgitem-actions:hover {
  opacity: 1;
}

.imgitem-preview {
  cursor: pointer;
  margin-right: 15px;
}

.imgitem-delete {
  cursor: pointer;
}
</style>
<style>
.itemfile .el-upload.el-upload--text {
  display: none;
}
</style>
